package com.baidu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;

@Controller
@RequestMapping("/user")
public class UploadController {
    @RequestMapping(value = "/first")
    public String doFirst(MultipartFile uploadFile, HttpSession session)
            throws Exception {
        if (uploadFile.getSize() > 0) {
            System.out.printf("1111111111111111111111111111111");
            String filename = uploadFile.getOriginalFilename();
            if (filename.endsWith("jpg") || filename.endsWith("gif") || filename.endsWith("png")) {
                String leftPath = session.getServletContext().getRealPath("/images");
                File file = new File(leftPath, filename);
                uploadFile.transferTo(file);
            }
        } else {
            return "error";
        }
        return "welcome";

    }
}
